package com.army.study;

import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;
import ohos.agp.utils.Color;
import ohos.agp.utils.Point;
import ohos.app.Context;

public class PointsOverlayView extends Component {

    Point[] points;
    private Paint paint;

    public PointsOverlayView(Context context) {
        super(context);
        init();
    }

    public PointsOverlayView(Context context, AttrSet attrSet) {
        super(context, attrSet);
        init();
    }

    public PointsOverlayView(Context context, AttrSet attrSet, String styleName) {
        super(context, attrSet, styleName);
        init();
    }

    public PointsOverlayView(Context context, AttrSet attrSet, int resId) {
        super(context, attrSet, resId);
        init();
    }

    private void init() {
        paint = new Paint();
        paint.setColor(Color.YELLOW);
        paint.setStyle(Paint.Style.FILL_STYLE);
    }

    public void setPoints(Point[] points) {
        this.points = points;
        addDrawTask(new PointDrawTask());
        invalidate();
    }

    //draw 4 corner points of QR.
    public class PointDrawTask implements DrawTask {
        @Override
        public void onDraw(Component component, Canvas canvas) {
            if (points != null) {
                for (Point pointF : points) {
                    canvas.drawCircle(pointF.getPointX(), pointF.getPointY(), 10, paint);
                }
            }
        }
    }
}
